#include "BasicString.h"

namespace utility
{
	BasicStringA::BasicStringA(void)
	{
	}
	BasicStringA::BasicStringA( castr_t lpsz )
	{
		m_str = lpsz;
	}
	BasicStringA::BasicStringA( astring_t & str )
	{
		m_str = str;
	}
	BasicStringA::BasicStringA( BasicStringA & str )
	{
		m_str = str.m_str;
	}
	BasicStringA::~BasicStringA(void)
	{
	}
	bool BasicStringA::operator==( const BasicStringA & str )
	{
		return m_str == str.m_str;
	}
	bool BasicStringA::operator==( const astring_t & str )
	{
		return m_str == str;
	}
	bool BasicStringA::operator==( castr_t lpsz )
	{
		return m_str == lpsz;
	}

	BasicStringA & BasicStringA::operator=( const BasicStringA & str )
	{
		this->m_str = str.m_str;
		return *this;
	}
	BasicStringA & BasicStringA::operator=( const astring_t & str )
	{
		this->m_str = str;
		return *this;
	}
	BasicStringA & BasicStringA::operator=( castr_t lpsz )
	{
		this->m_str = lpsz;
		return *this;
	}

	int BasicStringA::Find( castr_t lpsz, int pos )
	{
		int poss = m_str.find( lpsz, pos );
		return poss;
	}
	int BasicStringA::Find( const astring_t & str, int pos )
	{
		int poss = m_str.find( str, pos );
		return poss;
	}
	int BasicStringA::Find( const BasicStringA & str, int pos)
	{
		int poss = m_str.find( str.m_str, pos );
		return poss;
	}
	int BasicStringA::Find( char ch, int pos )
	{
		int poss = m_str.find( ch, pos );
		return pos;
	}

	void BasicStringA::Trim()
	{
		TrimLeft();
		TrimRight();
	}
	void BasicStringA::TrimLeft()
	{
		int begin = 0;
		size_t len = m_str.length();
		while( begin < len )
		{
			if( m_str[begin] != ' ' )
				break;
			begin++;
		}
		m_str = m_str.substr( begin );
	}
	void BasicStringA::TrimRight()
	{
		int begin = m_str.length();
		while( begin > 0 )
		{
			if( m_str[begin-1] != ' ' )
				break;
			begin--;
		}
		m_str = m_str.substr( 0, begin );
	}

	//////////////////////////////////////////////////////////////////////////
	BasicStringW::BasicStringW(void)
	{
	}
	BasicStringW::BasicStringW( cwstr_t lpsz )
	{
		m_str = lpsz;
	}
	BasicStringW::BasicStringW( wstring_t & str )
	{
		m_str = str;
	}
	BasicStringW::BasicStringW( BasicStringW & str )
	{
		m_str = str.m_str;
	}
	BasicStringW::~BasicStringW(void)
	{
	}
	bool BasicStringW::operator==( const BasicStringW & str )
	{
		return m_str == str.m_str;
	}
	bool BasicStringW::operator==( const wstring_t & str )
	{
		return m_str == str;
	}
	bool BasicStringW::operator==( cwstr_t lpsz )
	{
		return m_str == lpsz;
	}

	BasicStringW & BasicStringW::operator=( const BasicStringW & str )
	{
		this->m_str = str.m_str;
		return *this;
	}
	BasicStringW & BasicStringW::operator=( const wstring_t & str )
	{
		this->m_str = str;
		return *this;
	}
	BasicStringW & BasicStringW::operator=( cwstr_t lpsz )
	{
		this->m_str = lpsz;
		return *this;
	}

	int BasicStringW::Find( cwstr_t lpsz, int pos )
	{
		int poss = m_str.find( lpsz, pos );
		return poss;
	}
	int BasicStringW::Find( const wstring_t & str, int pos )
	{
		int poss = m_str.find( str, pos );
		return poss;
	}
	int BasicStringW::Find( const BasicStringW & str, int pos)
	{
		int poss = m_str.find( str.m_str, pos );
		return poss;
	}
	int BasicStringW::Find( wchar_t ch, int pos )
	{
		int poss = m_str.find( ch, pos );
		return poss;
	}

	void BasicStringW::Trim()
	{
		TrimLeft();
		TrimRight();
	}
	void BasicStringW::TrimLeft()
	{
		int begin = 0;
		size_t len = m_str.length();
		while( begin < len )
		{
			if( m_str[begin] != L' ' )
				break;
			begin++;
		}
		m_str = m_str.substr( begin );
	}
	void BasicStringW::TrimRight()
	{
		int begin = m_str.length();
		while( begin > 0 )
		{
			if( m_str[begin-1] != L' ' )
				break;
			begin--;
		}
		m_str = m_str.substr( 0, begin );
	}
}
